<!doctype html>
<%@page import="com.cn.ccp.util.Contants"%>
<%@ page contentType="text/html; charset=utf-8" %>
<%
 request.setCharacterEncoding("utf-8"); // 这句话很重要，否则遇到中文就出错~
%>
<jsp:directive.page import="com.cn.ccp.bean.UserBean" />
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
<html>
<f:view>
<f:loadBundle var="messages" basename="messages"></f:loadBundle>
<head>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<title><h:outputText value="#{messages['system_title']}" /></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- styles -->
    <link href="<%=request.getContextPath()%>/css/bootstrap.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/css/bootstrap-responsive.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/css/custom.css" rel="stylesheet">
    <!--[if lt IE 9]>
      <script src="../../../js/html5.js"></script>
    <![endif]-->
    <!-- Fav and touch icons -->
  <link rel="apple-touch-icon-precomposed" sizes="144x144" href="<%=request.getContextPath()%>/images/icon/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="<%=request.getContextPath()%>/images/icon/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="<%=request.getContextPath()%>/images/icon/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="<%=request.getContextPath()%>/images/icon/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="<%=request.getContextPath()%>/images/icon/favicon.png">
<link href="<%=request.getContextPath()%>/css/upload/default.css" rel="stylesheet" type="text/css" />
<link href="<%=request.getContextPath()%>/css/upload/uploadify.css" rel="stylesheet" type="text/css" />
<script src="<%=request.getContextPath()%>/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/upload/swfobject.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/upload/jquery.uploadify.v2.0.1.js"></script>
    <%
    int uid = 0 ;
    String fileType = (String)session.getAttribute(Contants.FILE_TYPE_FILE);
		UserBean users = (UserBean) session.getAttribute("userBean");
			if ((users == null) || (users.getUserName().equals(""))) {
	}else{
		uid = users.getId();
	}
	%>
	<%
		String path = request.getContextPath();
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	%>
	<script type="text/javascript">
	var fileType = '<%=fileType%>' ;
		function ispositive(strnumber) {
			re = /^[0-9]+.{0,1}[0-9]{0,2}$/;
			var str = strnumber.replace(/(^s*)|(s*$)/g, "");
			if (str == "")
				return true;
			else
				return (re.test(str)) ? true : false;
		}
		var uploadFileName = "";
		function insertTitle(tValue){ 
			exts = tValue.split(".");
			if(exts.length < 1){
				alert("错误，请上传正确的文件");
				return ;
			}
			ext = exts[1].toUpperCase();
			imageLayout = document.getElementById("imagelayoutId").value.toUpperCase() ;
			if(imageLayout.indexOf(ext) == -1){
				alert("错误，请上传正确的文件格式");
				return ;
			}
			uploadFileName = tValue ;
		  // var t1 = tValue.lastIndexOf("\\");  
		   //var t2 = tValue.lastIndexOf(".");  
		   //if(t1 >= 0 && t1 < t2 && t1 < tValue.length){  
		   // document.getElementById("file").value = tValue.substring(t1 + 1, t2);  
		  // }  
		} 
		function uploadFormSubmit(){
			if(uploadFileName == ''){
				return false;
			}
			document.getElementById("formid:section_file_name").value = uploadFileName ;
			
			return true ;
		}
		var uploadSourseFileName = "" ;//多个文件用分号隔开
		var uplaodFileName = "";//上传文件后的文件，分号隔开
		$(document).ready(function() {
			$("#uploadify").uploadify({
				'uploader'       : '<%=request.getContextPath()%>/flexpaper/uploadify.swf',
				//'script'         : 'upload!doUpload.action',
				'script'         : '<%=basePath%>/servlet/UploadCourseFile?uid='+<%=uid%>,
				'cancelImg'      : '<%=request.getContextPath()%>/images/cancel.png',
				'folder'         : 'uploads',
				'queueID'        : 'fileQueue',
				'auto'           : true,
				'multi'          : true,
				//'simUploadLimit' : 1,
				'buttonText'	 : 'upload' ,
				'fileDesc'       : '支持格式:'+fileType, //如果配置了以下的'fileExt'属性，那么这个属性是必须的  
                'fileExt'        : fileType,//允许的格式 
				'onComplete': function (event, queueID, fileObj, response, data) { 
					//alert(response);
					isAllowSubmit = true ;
					if(response == ''){
						 $("#formid:imageError").val("上传文件失败");
						 return ;
					}
					//alert($("#formid:hiddenImagePath").val());
					//alert(fileObj.name + "--"+response);
					$("#courseImageId").show();
					
					var sFile = fileObj.name ;
					if(uploadSourseFileName.indexOf(sFile) == -1)
						uploadSourseFileName += sFile+";";
					if(uplaodFileName.indexOf(response) == -1)
						uplaodFileName += response+";";
					document.getElementById("courseImageId").innerHTML = "文件:"+uploadSourseFileName+" 上传成功" ;
					document.getElementById("formid:hidd_source_file_url").value = uploadSourseFileName;
					document.getElementById("formid:hidd_section_file_name").value = sFile.split(".")[0];
					document.getElementById("formid:hidd_section_file_type").value = sFile.split(".")[1];
					document.getElementById("formid:hidd_section_file_url").value = uplaodFileName;
                },  
                'onError': function(event, queueID, fileObj) {  
					isAllowSubmit = true ;
                    $("#formid:imageError").val("上传文件失败");
					$("#courseImageId").show();
                },  
                'onCancel': function(event, queueID, fileObj){  
                	isAllowSubmit = true ;
        			$("#courseImageId").show();
                } ,
                'onSelect': function(event, queueID, fileObj){
                	isAllowSubmit = false; 
                	$("#submitButton").attr("disabled","true");
        			$("#courseImageId").hide();
                } ,
                'onAllComplete': function(event,data){
                	uploadSourseFileName = "" ;
            		uplaodFileName = "";
                }
                
                
			});
			
			
			
			var image = document.getElementById("formid:hidd_source_file_url").value;
			if(image != ''){
				document.getElementById("courseImageId").innerHTML = image;
			}
   			$("#courseImageId").show();
		});
		
		var isAllowSubmit = true ;
		function submitCheck(){
			if(!isAllowSubmit){
				alert("文件正在上传，请稍后提交。");
				return false;
			}	
		}
		
	</script>
</head>
<body class="bg-white" style="overflow-x:hidden;">
		<h:form id="formid" styleClass="form-horizontal"
			style="margin-left: 20px;margin-right: 20px">
			<div class="row page-head">
				<h3 class="page-title">
					<i class="n-icon-selection  n-icon-black"></i><h:outputText value="#{messages['course_page_course']}"/>&nbsp;&gt;&nbsp;<b><h:outputText value="#{messages['course_page_chapter_title']}" /></b>
				</h3>
			</div>
				<h:inputHidden value="#{courseAction.courseContentBean.id}"></h:inputHidden>
				
				<h:inputHidden id="hidd_source_file_url" value="#{courseAction.courseContentBean.source_file_url}"></h:inputHidden>
				<h:inputHidden id="hidd_section_file_name" value="#{courseAction.courseContentBean.section_file_name}"></h:inputHidden>
				<h:inputHidden id="hidd_section_file_type" value="#{courseAction.courseContentBean.section_file_type}"></h:inputHidden>
				<h:inputHidden id="hidd_section_file_url" value="#{courseAction.courseContentBean.section_file_url}"></h:inputHidden>
				
                <fieldset>
					<legend>基本信息</legend>
					<div class="form-white">
						<div class="control-group">
							<label class="control-label" for=""><h:outputText value="#{messages['course_content_page_number']}" /></label>
							<div class="controls">
								<h:selectOneMenu id="chapter_number" value="#{courseAction.courseContentBean.chapter_number}" disabled="#{courseAction.courseContentBean.updateState}">
									<f:selectItem itemLabel="#{messages['messages_select']}" itemValue="-1" />
									<f:selectItems value="#{publicAction.couresCountSelectItem}" />
									<a4j:support event="onchange" action="#{courseAction.numberOnkeyUpEvent}" reRender="chapter_title,section_number,can_browse"></a4j:support>
								</h:selectOneMenu>
								<span class="help-inline"><h:message for="chapter_number" style="color:red" /></span>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" for=""><h:outputText value="#{messages['course_content_page_chapter_title']}" /></label>
							<div class="controls">
								<h:inputText id="chapter_title" value="#{courseAction.courseContentBean.chapter_title}"   disabled="#{courseAction.disabled}">
								</h:inputText>
								<span class="help-inline"><h:message for="chapter_title" style="color:red" /></span>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" for=""><h:outputText value="#{messages['course_content_page_section_number']}" /></label>
							<div class="controls">
								<h:inputText id="section_number" value="#{courseAction.courseContentBean.section_number}"  disabled="true">
								</h:inputText>
								<span class="help-inline"><h:message for="section_number" style="color:red" /></span>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" for=""><h:outputText value="#{messages['course_content_page_file_type']}" /></label>
							<div class="controls">
								<h:outputText value="#{publicAction.uploadFileLayout},#{publicAction.uploadVideoLayout}" ></h:outputText>
								<span class="help-inline"><h:outputText  /></span>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" for=""><h:outputText value="#{messages['course_content_page_file_name']}" /></label>
							<div class="controls">
								<input type="file" name="uploadify" id="uploadify"  onchange="javascripte:alert(111)"/>
								<span class="help-inline"><h:outputText id="fileNameid"></h:outputText></span>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" for=""><h:outputText id="image" value=""></h:outputText></label>
							<div class="controls">
								<div id="fileQueue" style="height: 60px "></div>
								<span class="help-inline"><h:outputText id="imageError"></h:outputText></span>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" for=""><h:outputText id="image2" value=""></h:outputText></label>
							<div class="controls">
								<div id="courseImageId"></div>
								<span class="help-inline"><h:outputText id="imageError"></h:outputText>
								<h:message for="image2" style="color:red" /></span>
							</div>
						</div>
							
						
						<div class="control-group">
							<label class="control-label" for=""><h:outputText value="#{messages['course_content_page_can_browse']}" /></label>
							<div class="controls">
								<h:selectOneRadio id="can_browse" value="#{courseAction.courseContentBean.can_browse}"  disabled="#{courseAction.disabled}" >
									<f:selectItem itemValue="0" itemLabel="#{messages['btn_no']}" />
									<f:selectItem itemValue="1" itemLabel="#{messages['btn_yes']}" />
								</h:selectOneRadio>
								<span class="help-inline"><h:message for="can_browse" style="color:red" /></span>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" for=""><h:outputText value="#{messages['course_content_page_other']}" /></label>
							<div class="controls">
								<h:inputTextarea id="other" value="#{courseAction.courseContentBean.other}" cols="3"  disabled="#{courseAction.disabled}"/>
								<span class="help-inline"><h:message for="other" style="color:red" /></span>
							</div>
						</div>
					</div>
				</fieldset>
	            <div class="form-actions">
					<h:commandButton id="submitButton" value="#{messages['btn_submit']}" action="#{courseAction.editCourseContent}" styleClass="btn btn-primary" onclick="return submitCheck();"  rendered="#{courseAction.hiddenButton}"/>
					<h:commandButton value="#{messages['btn_cancel']}"  styleClass="btn" action="#{courseAction.editCourseContentCancel}"/>
	            </div>
		</h:form>
		
		<script src="<%=request.getContextPath()%>/js/bootstrap.js"></script>
</body>
</f:view>
</html>
